package com.blog.service.impl;

import com.blog.dao.UserDao;
import com.blog.dao.impl.UserDaoImpl;
import com.blog.pojo.User;
import com.blog.service.UserService;

import java.util.List;

public class UserServiceImpl implements UserService {
    private UserDao userDao=new UserDaoImpl();
    @Override
    public User addUser(User user) {
        userDao.addUser(user);
        return user;
    }

    @Override
    public boolean delete(int id) {
       int update= userDao.deleteUser(id);
       if(update>0){
           return true;
       }
        return false;
    }

    @Override
    public boolean update(User user) {
      int update= userDao.updateUser(user);
        if(update>0){
            return true;
        }
        return false;

    }

    @Override
    public List<User> findAll() {
        return userDao.findAll();

    }

    @Override
    public User findById(int id) {
      return   userDao.findUserById(id);

    }

    @Override
    public boolean addExperience(int uId, int experiencePoints) {
        int update = userDao.addExperience(uId, experiencePoints);
        if(update>0){
            return true;

        }
        return false;
    }

    @Override
    public boolean reduceExperience(int uId, int experiencePoints) {
        int update = userDao.reduceExperience(uId, experiencePoints);
        if(update>0){
            return true;
        }
        return false;
    }

    @Override
    public int findExperience(int uId) {
        return userDao.findExperience(uId);
    }

    @Override
    public User findByUserName(String username) {
        return userDao.findByUserName( username);
    }
}
